package dataProces;
import java.sql.*;
public class DBC {
    private Statement statement=null;
    private ResultSet rSet=null;
    private Connection connection=null;
    FileOpera fio =new FileOpera();
    public void mysqlConnection(){
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            String url = "jdbc:mysql://localhost:3306/idiom_link?useUnicode=true&characterEncoding=UTF-8";
            connection=DriverManager.getConnection(url, "root", "123456");
            statement=connection.createStatement();
        }catch(Exception e){
            fio.logFile("数据库连接异常:"+e.getMessage());
        }
    }
    public boolean mysqlUpdate(String sql){
        boolean update=true;
        try{
            fio.logFile("数据库操作语句:"+sql);
            statement.execute(sql);
        }catch(SQLException e){
            update=false;
            fio.logFile("数据库操作异常:"+e.getMessage());
        }
        return update;
    }
    public ResultSet mysqlQuery(String sql){
        try{
            fio.logFile("数据库查询语句:"+sql);
            rSet=statement.executeQuery(sql);
        }catch(SQLException e){
            fio.logFile("数据库查询异常:"+e.getMessage());
        }
        return rSet;
    }
    public void mysqlClose(){
        try{
            statement.close();
            connection.close();
        }catch(SQLException e){
            fio.logFile("数据库释放异常:"+e.getMessage());
        }
    }
}
